<template>
  <div class="dashboard-editor-container">
    <!--    <github-corner class="github-corner"/>-->
    <!-- <h1>欢迎使用SCRM管理系统</h1> -->
    <!-- 数据展示 -->
    <!-- <div class="zhanshi">
      <div class="">
        <span>1515</span>
        <span>数据展示</span>
      </div>
    </div> -->
    <!-- 数据展示 -->
    <div class="list">
      <div class="list_div" @click="selectMeetingUsers">
        <div class="name">销售管理</div>
        <div class="num">{{ sales }}</div>
        <div class="icon">
          <img
            src="https://scrm.mini.xinpu8.com/voice/picture/mini_img/zuanshi.png"
          />
        </div>
      </div>
      <div class="list_div">
        <div class="name">客户管理</div>
        <div class="num">{{ userCount }}</div>
        <div class="icon">
          <img
            src="https://scrm.mini.xinpu8.com/voice/picture/mini_img/caidan.png"
          />
        </div>
      </div>
      <div class="list_div">
        <div class="name">线索管理</div>
        <div class="num">{{ clueCount }}</div>
        <div class="icon">
          <img
            src="https://scrm.mini.xinpu8.com/voice/picture/mini_img/weizhi.png"
          />
        </div>
      </div>
      <div class="list_div list_img">
        <img
          src="https://scrm.mini.xinpu8.com/voice/picture/mini_img/huan.png"
        />
      </div>
    </div>
    <!-- 任务和男女 -->
    <div class="task">
      <!-- 任务 -->
      <div class="task_left">
        <div class="task_title">
          <span class="leibiao">任务列表</span>
          <span class="quan">全部数量</span>
          <span class="task_num">{{ zNum }}</span>
          <!-- <span>任务列表</span> -->
        </div>
        <div class="myTu">
          <div id="myChart" :style="{ width: '100%', height: '100%' }"></div>
        </div>
      </div>
      <div class="task_right">
        <div class="grd_title">
          <span>客户分析</span>
          <span>查看更多</span>
        </div>
        <div class="nan">
          <div class="nan_one">
            <div class="one">
              <div>1</div>
              <div>男性</div>
            </div>
            <div class="bai">{{ nan }}</div>
          </div>
          <div class="jindu">
            <div class="yan" :style="{ width: nan }"></div>
          </div>
        </div>
        <div class="nan">
          <div class="nan_one">
            <div class="one">
              <div>2</div>
              <div>女性</div>
            </div>
            <div class="bai">{{ nv }}</div>
          </div>
          <div class="jindu">
            <div class="yan yan1" :style="{ width: nv }"></div>
          </div>
        </div>
        <div class="nan">
          <div class="nan_one">
            <div class="one">
              <div>3</div>
              <div>未知</div>
            </div>
            <div class="bai">{{ weizhi }}</div>
          </div>
          <div class="jindu">
            <div class="yan yan2" :style="{ width: weizhi }"></div>
          </div>
        </div>
      </div>
      <!-- 男女 -->
      <div></div>
    </div>
    <!-- 企业管理 -->
    <div class="admin">
      <!-- 企业管理 -->
      <div class="ad_left">
        <div class="ad_title">企业管理</div>
        <div class="myId">
          <div id="myChartId" :style="{ width: '100%', height: '100%' }"></div>
        </div>
      </div>
      <!-- 图文管理 -->
      <div class="ad_right">
        <div class="ad_title">图文管理</div>
        <div class="myId">
          <div id="myChartZhu" :style="{ width: '100%', height: '100%' }"></div>
        </div>
      </div>
    </div>
    <!-- <panel-group @handleSetLineChartData="handleSetLineChartData" /> -->
  </div>
</template>

<script>
  import "@/assets/jwxwork-1.0.0";
  import {indexCount, indexList, Wecont, Welist} from "@/api/stats";
  import GithubCorner from "@/components/GithubCorner";
  import PanelGroup from "./components/PanelGroup";
  import LineChart from "./components/LineChart";
  import RaddarChart from "./components/RaddarChart";
  import PieChart from "./components/PieChart";
  import BarChart from "./components/BarChart";
  import TransactionTable from "./components/TransactionTable";
  import TodoList from "./components/TodoList";
  import BoxCard from "./components/BoxCard";
  import {indexData, orderCount, siteCount} from "@/api/stats";
  import echarts from "echarts";

  const lineChartData = {
    newVisitis: {
      expectedData: [100, 120, 161, 134, 105, 160, 165],
      actualData: [120, 82, 91, 154, 162, 140, 145],
    },
    messages: {
      expectedData: [200, 192, 120, 144, 160, 130, 140],
      actualData: [180, 160, 151, 106, 145, 150, 130],
    },
    purchases: {
      expectedData: [80, 100, 121, 104, 105, 90, 100],
      actualData: [120, 90, 100, 138, 142, 130, 130],
    },
    shoppings: {
      expectedData: [130, 140, 141, 142, 145, 150, 160],
      actualData: [120, 82, 91, 154, 162, 140, 130],
    },
  };

  export default {
    name: "DashboardAdmin",
    name: "echarts",
    components: {
      GithubCorner,
      PanelGroup,
      LineChart,
      RaddarChart,
      PieChart,
      BarChart,
      TransactionTable,
      TodoList,
      BoxCard,
    },
    data() {
      return {
        lineChartData: [],
        date: [],
        orderLineChartData: [],
        orderDate: [],
        userCount: 0,
        siteCount: 0,
        money: 0,
        publicUserCount: 0,
        clueCount: 0,
        publicClueCount: 0,
        count: 0,
        sales: 0,
        nan: "0",
        nv: "0",
        weizhi: "0",
        phon: [],
        zNum: 0,
        list: [],
      };
    },
    mounted() {
      // this.handleSetLineChartData()
      // this.handleInit()
      // this.aaaa();
      // this.bbbb();
      // this.cccc();
      this.handleInt();
    },
    methods: {
      // handleInit() {
      //   siteCount(this.name, this.page, this.size).then(res => {
      //     this.tableData = res.result.resList
      //     this.total = Number(res.result.total)
      //   })
      // },
      handleSetLineChartData(type) {
        indexData().then((res) => {
          this.date = res.result.date;
          this.lineChartData = res.result.count;
        });
        orderCount().then((res) => {
          this.orderDate = res.result.date;
          this.orderLineChartData = res.result.count;
        });
      },
      selectMeetingUsers() {
        var that = this;
      },
      handleInt() {
        const _this = this;
        indexList().then((res) => {
          console.log(res);
          _this.userCount = res.result.userCount;
          // _this.siteCount = res.result.orderCount.count
          _this.publicUserCount = res.result.publicUserCount;
          (_this.clueCount = res.result.clueCount),
            (_this.publicClueCount = res.result.publicClueCount);
          _this.count = res.result.count;
          _this.sales = res.result.sales;
          // _this.money = res.result.orderCount.price;
          let cont = res.result.userNum;
          let namum = res.result.manNum;
          let womanNum = res.result.womanNum;
          _this.phon = res.result.photoNum;
          _this.tasklist = res.result.taskNum;
          if (cont == 0) {
            let nan = 0 + "%";
            let nv = 0 + "%";
            let wei = 0 + "%";
            _this.nan = nan;
            _this.nv = nv;
            _this.weizhi = wei;
          } else {
            let nan = ((namum / cont) * 100).toFixed(2) + "%";
            let nv = ((womanNum / cont) * 100).toFixed(2) + "%";
            let wei = (((cont - womanNum - namum) / cont) * 100).toFixed(2) + "%";
            _this.nan = nan;
            _this.nv = nv;
            _this.weizhi = wei;
          }

          _this.aaaa();
          _this.bbbb();
          _this.cccc();
        });
      },
      aaaa() {
        let list = this.tasklist;
        let array = [];
        let Ylist = [];
        for (var i = 0; i < list.length; i++) {
          let aaa = list[i].createTime.split(" ");
          array.push(aaa[0]);
          Ylist.push(list[i].finish);
          this.zNum += list[i].finish;
        }
        if (array.length == 0) {
          array = ["-", "-", "-", "-", "-", "-", "-"];
        }
        if (Ylist.length == 0) {
          Ylist = [0, 0, 0, 0, 0, 0, 0];
        }
        let myChart = this.$echarts.init(document.getElementById("myChart"));
        // 绘制图表
        myChart.setOption({
          title: {
            text: "",
          },
          tooltip: {
            trigger: "axis",
          },
          grid: {
            left: "0%",
            right: "4%",
            bottom: "5%",
            top: "2%",
            containLabel: true,
            borderWidth: "0",
            show: "true",
            borderColor: "#ccc",
            backgroundColor: "rgba(0,0,0,0)",
          },
          toolbox: {
            feature: {},
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: array,
          },
          yAxis: {
            type: "value",

            axisLine: {
              show: false,
              lineStyle: {
                // type: "dashed", //设置网格线类型 dotted：虚线   solid:实线
                // 设置y轴颜色
                // color: '#fff'
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed",
              },
            },
          },
          series: [
            {
              name: "",
              type: "line",
              stack: "总量",
              data: Ylist,
              color: "#466AF0",
            },
          ],
        });
      },
      bbbb() {
        let myChartId = this.$echarts.init(document.getElementById("myChartId"));
        // 绘制图表
        myChartId.setOption({
          title: {
            text: "",
          },
          tooltip: {
            trigger: "axis",
          },
          grid: {
            left: "0%",
            right: "4%",
            bottom: "5%",
            top: "2%",
            containLabel: true,
            borderWidth: "1",
            show: "true",
            borderColor: "#ccc",
            backgroundColor: "rgba(0,0,0,0)",
          },
          toolbox: {
            feature: {},
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
          },
          yAxis: {
            type: "value",
            axisLine: {
              show: false,
              lineStyle: {
                // 设置y轴颜色
                // color: '#fff'
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed",
              },
            },
          },
          series: [
            {
              name: "",
              type: "line",
              stack: "总量",
              data: [120, 132, 101, 134, 90, 230, 300],
              color: "#466AF0",
            },
          ],
        });
      },
      cccc() {
        let list = this.phon;
        let time = [];
        let array = [];
        for (var i = 0; i < list.length; i++) {
          time.push(list[i].ctreateTime);
          if (list[i].num == null) {
            list[i].num = 0;
          }
          array.push(list[i].num);
        }
        let myChartZhu = this.$echarts.init(
          document.getElementById("myChartZhu")
        );
        myChartZhu.setOption({
          xAxis: {
            type: "category",
            data: time.reverse(),
          },
          yAxis: {
            type: "value",
            splitLine: {
              show: true,
              lineStyle: {
                type: "dashed",
              },
            },
          },
          grid: {
            left: "0%",
            right: "4%",
            bottom: "5%",
            top: "2%",
            containLabel: true,
            borderWidth: "0",
            show: true,
            borderColor: "#ccc",
            backgroundColor: "rgba(0,0,0,0)",
          },
          series: [
            {
              data: array.reverse(),
              type: "bar",
              barGap: "5%",
              showBackground: true,
              barCategoryGap: "60%",
              backgroundStyle: {
                color: "rgba(232,236,239,1)",
              },
              itemStyle: {
                normal: {
                  color: "#4E73F4",
                },
              },
            },
          ],
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    // background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0px;
      border: 0;
      right: 0;
    }

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  .list {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .list_div {
    width: 23%;
    height: 184px;
    // opacity: 1;
    background: #ffffff;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    border-color: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 23px 30px;
    box-sizing: border-box;
    position: relative;
  }

  .list_img {
    padding: 0px;
  }

  .name {
    font-size: 20px;
  }

  .num {
    color: #466bf1;
    font-size: 26px;
    margin-top: 30px;
  }

  .myTu {
    flex: 1;
    // width: 500px;
    height: 300px;
  }

  .icon {
    position: absolute;
    width: 55px;
    height: 55px;
    opacity: 0.1;
    // background: #387dff;
    border-radius: 50%;
    top: 30px;
    right: 30px;
  }

  .icon img {
    width: 55px;
    height: 55px;
  }

  .icon_er {
    background: #75e9d7;
  }

  .icon_san {
    background: #f780a5;
  }

  .huan {
    margin-left: 36px;
    margin-top: 40px;
    font-size: 26px;
  }

  .hName {
    margin-left: 36px;
    font-size: 26px;
    margin-top: 5px;
  }

  .leibiao {
    color: #334681;
    font-size: 18px;
  }

  .quan {
    color: #6c7293;
    font-size: 12px;
    margin: 21px 0 7px 0;
  }

  .task_num {
    color: #466bf1;
    font-size: 26px;
    margin-top: 10px;
  }

  .task {
    width: 100%;
    margin: 20px 0;
    display: flex;
    justify-content: space-between;
  }

  .task_left {
    width: 78%;
    height: 320px;
    opacity: 1;
    background: #ffffff;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    border-color: rgba(0, 0, 0, 0.05);
    display: flex;
    padding: 30px;
    box-sizing: border-box;
  }

  .task_right {
    width: 20%;
    height: 320px;
    opacity: 1;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0px 0px 15px 0px rgba(231, 236, 239, 0.1);
    background: #ffffff;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    border-color: rgba(0, 0, 0, 0.05);
    padding: 30px;
    box-sizing: border-box;
  }

  .task_title {
    width: 15%;
  }

  .task_title span {
    display: block;
  }

  .grd_title {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .grd_title span:first-child {
    color: #334681;
    font-size: 16px;
  }

  .grd_title span:last-child {
    color: #8590b3;
    font-size: 12px;
  }

  .one {
    display: flex;
    font-size: 12px;
    // margin-top: 15px;
  }

  .one div:first-child {
    width: 15px;
    height: 15px;
    // opacity: 0.05;
    background: rgba(51, 70, 129, 0.3);
    line-height: 15px;
    color: #fff;
    text-align: center;
    border-radius: 2px;
    margin-right: 10px;
  }

  .bai {
    font-size: 12px;
  }

  .nan {
    margin-top: 25px;
  }

  .nan_one {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .jindu {
    width: 100%;
    height: 10px;
    // opacity: 0.03;
    background: rgba(51, 70, 129, 0.1);
    border-radius: 2px;
    margin-top: 15px;
  }

  .yan {
    width: 60%;
    height: 10px;
    background: linear-gradient(305deg, #466bf1 95%, #6988fe 95%, #5533ff 95%);
    border-radius: 2px;
  }

  .yan1 {
    width: 45%;
    background: linear-gradient(121deg, #f76994 26%, #e85373 93%);
    border-radius: 2px;
  }

  .yan2 {
    width: 0%;
    background: linear-gradient(124deg, #facf5f 27%, #feb84b 91%);
    border-radius: 2px;
  }

  .admin {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }

  .ad_left {
    width: 49%;
    height: 420px;
    background: #ffffff;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    border-color: rgba(0, 0, 0, 0.05);
    padding: 30px;
    box-sizing: border-box;
  }

  .ad_right {
    width: 49%;
    height: 420px;
    background: #ffffff;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    border-color: rgba(0, 0, 0, 0.05);
    padding: 30px;
    box-sizing: border-box;
  }

  .ad_title {
    color: rgba(51, 70, 129, 1);
    font-size: 22px;
    margin-bottom: 15px;
  }

  .myId {
    width: 100%;
    height: 350px;
  }

  @media (max-width: 1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }

  .zhanshi {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
  }

  .zhanshi div {
    width: 25%;
    text-align: center;
  }

  .zhanshi div span {
    display: block;
  }
</style>
